package com.xique.door.service.impl;


import com.xique.door.bean.domain.PermissionGroupUser;
import com.xique.door.bean.request.permissionGroup.PermissionGroupUserRequest;
import com.xique.door.bean.search.PermissionGroupSelectUserSearch;
import com.xique.door.mapper.PermissionGroupUserMapper;
import com.xique.door.service.IPermissionGroupUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * 权限组用户Service业务层处理
 *
 * @author ww
 * @date 2021-06-17
 */
@Service
public class PermissionGroupUserServiceImpl implements IPermissionGroupUserService
{
    @Autowired
    private PermissionGroupUserMapper permissionGroupUserMapper;

    /**
     * 查看权限组用户列表
     *
     * @param groupIds
     * @return
     */
    @Override
    public List<PermissionGroupUser> selectPermissionGroupUserListByGroupIds(List<Long> groupIds) {
        if (groupIds.isEmpty()) {
            return new ArrayList<>();
        }
        return permissionGroupUserMapper.selectPermissionGroupUserListByGroupIds(groupIds);
    }

    /**
     * 查询权限组用户列表
     *
     * @param permissionGroupUser 权限组用户
     * @return 权限组用户
     */
    @Override
    public List<PermissionGroupUser> selectPermissionGroupUserList(PermissionGroupUser permissionGroupUser)
    {
        return permissionGroupUserMapper.selectPermissionGroupUserList(permissionGroupUser);
    }

    @Override
    public List<PermissionGroupUser> selectPermissionGroupUserListBySearch(PermissionGroupSelectUserSearch search) {
        if (search.getGroupId() == null && search.getUserIds().isEmpty()) {
            return new ArrayList<>();
        }
        return permissionGroupUserMapper.selectPermissionGroupUserListBySearch(search);
    }

    @Override
    public int batchDeletePermissionGroupUser(List<Long> ids) {
        if (ids.isEmpty()) {
            return 1;
        }
        return permissionGroupUserMapper.deletePermissionGroupUserByIds(ids);
    }

    @Override
    public int deletePermissionGroupUser(Long id) {
        return permissionGroupUserMapper.deletePermissionGroupUserById(id);
    }

    @Override
    public int batchInsertPermissionGroupUser(List<PermissionGroupUser> list) {
        if (list.isEmpty()) {
            return 1;
        }
        return permissionGroupUserMapper.batchInsertPermissionGroupUser(list);
    }

    @Override
    public List<PermissionGroupUser> selectAllocatedUserList(PermissionGroupUserRequest request) {
        return permissionGroupUserMapper.selectAllocatedUserList(request);
    }

    @Override
    public List<PermissionGroupUser> selectUnallocatedUserList(PermissionGroupUserRequest request) {
        return permissionGroupUserMapper.selectUnallocatedUserList(request);
    }
}
